#ifndef PARTICLE_H
#define PARTICLE_H

#include <chrono>

#include <vsg/core/ref_ptr.h>
#include <vsg/nodes/MatrixTransform.h>

enum class ParticleState {
	Flying,
	Done
};

class Particle {
public:
	Particle() = default;
	Particle(vsg::dvec3 pos, vsg::dvec3 speed, double dragCoefficient, vsg::vec4 color)
		: m_pos{ pos },
		m_speed{ speed },
		m_dragCoefficient{ dragCoefficient },
		m_color{ color } {};

	virtual ~Particle() {};

	virtual vsg::ref_ptr<vsg::Node> getNode();

	virtual void update(const std::chrono::nanoseconds& delt);

	void setPos(vsg::dvec3 pos) {
		m_pos = pos;
	}

	void setColor(vsg::vec4 color) {
		m_color = color;
        for (auto& color : *m_colors)
        {
            color.set(m_color.r, m_color.g, m_color.b, m_color.a);
        }
        m_colors->dirty();
	}

	void setDragCoefficient(double value) {
		m_dragCoefficient = value;
	}

	void setSpeed(vsg::dvec3 speed) {
		m_speed = speed;
	}

	bool isDone() {
		return m_state == ParticleState::Done;
	}

	void setMovePara(double theta, double A) {
		m_theta = theta;
		m_A = A;
	}

	virtual void activate();
protected:
	virtual void invalid();
protected:
	vsg::dvec3 m_pos{ 0.,0.,0. };
	double m_radius{ 0. };
	vsg::dvec3 m_speed{ 0.,0.,0. };
private:
	double m_dragCoefficient{ 0 };
protected:
	vsg::vec4 m_color{ 0.f, 0.f, 0.f, 0.f };
	ParticleState m_state{ ParticleState::Flying };
	vsg::ref_ptr<vsg::MatrixTransform> m_matrixTransform;
	std::chrono::nanoseconds m_duration{ 0 };
private:
	double m_theta{ 0.f };
	double m_mu{ 0.f };
	double m_A{ 0.f };
	vsg::ref_ptr<vsg::vec4Array> m_colors;
};

#endif
